import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {CommentModel} from "../../model/comment.model";
import {LocalStorage} from "../../utils/localstorage.utils";
import {COMMENT} from "../../api/comment.service";
import {USER} from "../../service/user.service";

/**
 * Generated class for the RatingPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-rating',
  templateUrl: 'rating.html',
})
export class RatingPage {
  comment:CommentModel;


  constructor(public ls:LocalStorage, public USER:USER,public COMMENT:COMMENT) {
    this.comment = new CommentModel(this.ls.get('commentNo'))
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad RatingPage');
  }

  commentScore(array, score, index) {
    for (let i = 0; i < this.comment[array].length; i++) {
      if (i > index) {
        this.comment[array][i] = false
      } else {
        this.comment[array][i] = true
      }
    }
    this.comment[score] = index + 1
    console.log(this.comment)
  }
  commentFunc(){
    this.COMMENT.comment(this.comment.genRequestData(),v=>{
      window.history.back();
    })
  }

}
